﻿<%@ Page Language="VB" %>

<%@ Import Namespace="paycircuit.com.google.iap" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
        
    ' Copyright (C) 2011 Paycircuit.com, Thinking Spot
    ' 
    ' Licensed under the Apache License, Version 2.0 (the 'License');
    ' you may not use this file except in compliance with the License.
    ' You may obtain a copy of the License at
    ' 
    ' http://www.apache.org/licenses/LICENSE-2.0
    ' 
    ' Unless required by applicable law or agreed to in writing, software
    ' distributed under the License is distributed on an 'AS IS' BASIS,
    ' WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    ' See the License for the specific language governing permissions and
    ' limitations under the License.        
    
    '*** I M P O R T A N T ***
    'use your credentials
    'This is a simple sample, you can define these in web.config if neeeded
    'When copying/pasting make sure you don't include spaces
    Dim MY_SELLER_ID As String = "YOUR SELLER ID"
    Dim MY_SELLER_SECRET As String = "YOUR SELLER SECRET"
    
    '*** I M P O R T A N T ***
    ' This sample DOES NOT INCLUDE required code for you to confirm/verify payment
    ' You must add code to check/verify successful payment/handling of your callback handler 
    '   which is processed asynchronously (separate from this web browser/client process).     
    
    Protected Sub Page_Load(sender As Object, e As System.EventArgs)
        
    End Sub
    
    Function theJWT() As String
        Try
            Dim HeaderObj As JWTHeaderObject = New JWTHeaderObject(JWTHeaderObject.JWTHash.HS256, "1", "JWT")
            Dim ClaimObj As InAppItemObject = New InAppItemObject("Some Widget App", "ASP.NET web forms vb test", "4.99", "USD", "some seller unique data", MY_SELLER_ID, 10)
            Return JWTHelpers.buildJWT(HeaderObj, ClaimObj, MY_SELLER_SECRET)
        Catch ex As Exception
            Return String.Empty
        End Try
    End Function
    
    
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <title>ASP.Net Web Forms (vb) In App Payments Sample</title>
    <meta name="description" content="A simple in-app payments demo page in ASP.NET web forms (vb)" />
    <meta name="author" content="edsf" />
    <link href="styles/global.min.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="http://www.google.com/jsapi">        //you should get your own Google key for this as well</script>
    <script type="text/javascript">
        google.load('payments', '1.0', {
            'packages': ['sandbox_config']

        });

        function purchase(callback) {
            goog.payments.inapp.buy({
                "parameters": {},
                "jwt": "<%=theJWT() %>",
                "success": function (result) {
                    if (typeof callback === "function") {
                        callback(true, result);
                    }
                },
                "failure": function (result) {
                    if (typeof callback === "function") {
                        callback(false, result);
                    }
                }
            }
        )
        };

        /*** S A M P L E   O N L Y ****
        *******************************
        !You should verify server side!
        *******************************                
        */
        var sampleParseResult = function (isgood, data) {
            var _console = (typeof window.console === "undefined");
            if (isgood) {
                var _str = "Verify Order No. " + data.response.orderId;
                _str += "\nDetails:\n";
                _str += data.request.name + " " + data.request.description + "\n";
                _str += data.request.price + "\n";
                alert(_str);
                if (!_console) {
                    console.log(data);
                }
            } else {
                alert("failed");
                if (!_console) {
                    console.log(data);
                }
            }
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div class="container_12" style="margin-top: 20px;">
        <div>
            <h1>
                In-App Payments Demo:
            </h1>
            <h5>
                Some Widget App</h5>
            <ul>
                <li>My Widget makes your Android Tablet fly</li>
                <li>Price: $4.99</li>
            </ul>
            <asp:Button ID="foo" Text="Buy Widget" runat="server" OnClientClick="purchase(sampleParseResult); return false;"
                Style="padding: 5px;" />
        </div>
    </div>
    </form>
</body>
</html>
